package hiho.ku._1234;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int t = in.nextInt();
		for (int i = 0; i < t; i++)
			run(in);
	}
	
	private static void run(Scanner in) {
		double x = in.nextDouble();
		if (x > 0.5)
			x = 1 - x;
		x = 1 - x * 2;
		double n = Math.log(x) / Math.log(0.5);
		double _n = Math.ceil(n);
		if (_n > 500)
			System.out.println(2002);
		else if (_n - n <= 1e-8)
			System.out.println(-1);
		else
			System.out.println(4 * (int)_n);
	}

}
